/**
 * Created by artheru on 2017/1/24.
 */

import bodyParser from 'body-parser';
import cors from 'cors';

export default function(ctx) {
    ctx.app.use(bodyParser.urlencoded({
        extended: true
    }));
    ctx.app.use(bodyParser.text());
    ctx.app.use(bodyParser.json({
        strict:false,
    }));
    ctx.app.use(cors()); //TODO: debug use
    ctx.app.use(function (req, res, next) {
        console.log('* ',req.url,' => ', req.body);
        try {
            req.body = JSON.parse(req.body);
        } catch (e) {
            //well, not json...
        }
        next();
    });
}